<div class="row-fluid ui-sortable">
		<div class="box span4">
			<div class="box-header well" data-original-title>
				<h2>Pengaturan Hak Akses</h2>
			</div>
			<div class="box-content">
				<div id="DataTables_Table_0_wrapper" class="dataTables_wrapper" role="grid">
				<table class="table" style="margin-top: -85%"> <thead>
					<tr>
					  <th style="width: 3%;"></th>
					  <th>Nama Fitur</th>
				  </tr>							  </thead>  <tbody>
					<?php $i=1; ?>
					<?php foreach($all_fitur as $fitur): ?>
						<label class="checkbox">
							<tr>
								<td class="center" style="width: 3%;"><input id="check-<?= $i; ?>" name="check-<?= $i; ?>" value="<?= $fitur['id_fitur']; ?>" type="checkbox" <?php if(isset($fitur['status'])) if($fitur['status'] == TRUE) echo "checked='checked'"; ?>></td>
								<td><?= $fitur['nama_fitur']; ?></td>
							</tr>
						</label>
						<?php $i++; ?>
					<?php endforeach; ?>
					</tbody>
				 </table>
				 <input type="hidden" id="id_role" value="<?= $id_role; ?>">
				 <center><button class="btn" onclick="submitHakAkses();">Simpan</button></center>
				 </div>
			</div>
		</div><!--/span-->
		
	</div>

<script>
	
	var fiturCount = <?= $fitur_count; ?>;
	function submitHakAkses(){
		var idFiturArr = "";
		var idRole = $('#id_role').val();
		for(var i=1; i<=fiturCount; i++){
			if(document.getElementById('check-'+i).checked){
				idFiturArr += $('#check-'+i).val()+",";
			} 
			
		}
		
		$.ajax({
			url: "<?= base_url(); ?>role/submit_hak_akses",
			type: "POST",
			data: "id_fitur="+idFiturArr+"&id_role="+idRole,
			success: function(msg){
				window.location = "<?= base_url(); ?>role";
			}
		});
		
	}
</script>